import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDPayment {
	/**id*/
	id,
	/**消耗货币数量*/
	costNum,
	/**充值货币id*/
	exItem,
	/**获得货币数量*/
	exNum,
	/**首充获得数量*/
	firstNum,

	/**枚举数量*/
	EnumCount
}



export class CDPayment{
	/**id*/
	public id: number;
	/**消耗货币数量*/
	public costNum: number;
	/**充值货币id*/
	public exItem: number;
	/**获得货币数量*/
	public exNum: number;
	/**首充获得数量*/
	public firstNum: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDPayment.id: return this.id;
			case E_CDPayment.costNum: return this.costNum;
			case E_CDPayment.exItem: return this.exItem;
			case E_CDPayment.exNum: return this.exNum;
			case E_CDPayment.firstNum: return this.firstNum;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDPayment.id: this.id = v; break;
			case E_CDPayment.costNum: this.costNum = v; break;
			case E_CDPayment.exItem: this.exItem = v; break;
			case E_CDPayment.exNum: this.exNum = v; break;
			case E_CDPayment.firstNum: this.firstNum = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDPayment> = new HashMap<number, CDPayment>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDPayment[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDPayment();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].costNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].exItem = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].exNum = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].firstNum = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDPayment{
		return this.datas ? this.datas.get(id) : null;
	}
}
